<template>
  <view>
    <view class="goods-list">
      <block v-for="(goods, i) in goodsList" :key="i">
        <view class="goods-item">
          <!-- 商品左侧图片区域 -->
          <view class="goods-item-left">
            <image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
          </view>
          <!-- 商品右侧信息区域 -->
          <view class="goods-item-right">
            <!-- 商品标题 -->
            <view class="goods-name">{{goods.goods_name}}</view>
            <view class="goods-info-box">
              <!-- 商品价格 -->
              <view class="goods-price">￥{{goods.goods_price}}</view>
            </view>
          </view>
        </view>
      </block>
    </view>
  </view>
</template>

<script>
  export default {
  data() {
    return {
      // 请求参数对象
      queryObj: {
        query: '',  // 查询关键词
        cid: '',  // 商品分类Id
        pagenum: 1,  // 页码值
        pagesize: 10   // 每页显示多少条数据
      },
      goodsList: [],// 商品列表的数据
      total: 0   // 总数量，用来判断数据是否请求完毕
    }
  },
  onLoad(options) {
    this.queryObj.query=options.query || ''
    this.queryObj.query=options.cid || ''
    this.getGoodsList()
  },
  methods: {
    async getGoodsList() {
      const { data:res } = await uni.$http.get('/goods/search', this.queryObj)
      if(res.meta.status!==200) return uni.$showMsg()
      console.log('getGoodsList',res)
      this.goodsList=res.message.goods
      this.total=res.message.total
    }
  }
 }
</script>

<style lang="scss">
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;
  .goods-item-left {
    margin-right: 5px;
    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
      // vertical-align: middle;
      // https://segmentfault.com/q/1010000000694663
    }
    
  }
  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .goods-name {
      font-size: 13px;
    }
    .goods-price {
      font-size: 16px;
      color: #c00000;
    }
  }
}
</style>
